import 'package:eplorex/pages/my/profile/edit_user_birthday_page.dart';
import 'package:eplorex/pages/payment/payment_demo_page.dart';
import 'package:eplorex/pages/root_page.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../providers/auth_provider.dart';
import 'login/welcome_page.dart';

class SplashPage extends StatefulWidget {
  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  @override
  void initState() {
    super.initState();
    Future.delayed(Duration(seconds: 3), () => _checkLogin());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: null,
      ),
      body: Container(),
    );
  }

  void _checkLogin() async {
    final authProvider = context.read<AuthProvider>();
    bool isLogin = await authProvider.isLoggedIn();
    if (isLogin) {
      Navigator.pushReplacement(
          context, MaterialPageRoute(builder: (context) => HomePage()));
    } else {
      Navigator.pushReplacement(
          context, MaterialPageRoute(builder: (context) => WelcomePage()));
    }
  }
}
